home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / compuserve-file-archive / 03 Demos and Info / C64PRN.TXT < prev    next >
Encoding:
Text File  |  2019-04-13  |  5.0 KB  |  143 lines

  1. This article describes how to connect a Commodore 64 compatible printer to an
  2. IBM PC compatible computer.  The information originally appeared in an article
  3. that I wrote for the Tech Forum section of the March 1995 issue of Nuts & Volts
  4. magazine.  This information may be used and distributed so long as proper
  5. credit is given to the author and Nuts & Volts magazine.  Copyright (C) 1995 by
  6. John Keyerleber and Nuts & Volts Magazine.
  7.  
  8. The problem with Commodore 64 compatible printers is that these devices use the
  9. Commodore synchronous serial interface to communicate with the C64.  An IBM PC
  10. compatible printer port is a parallel interface, however it is possible to use
  11. this parallel port to emulate the C64 serial interface by constructing a
  12. special cable and writing a little bit of software.
  13.  
  14. The cable is used to connect the PC DB25 pin parallel printer port to the 6 pin
  15. DIN serial port on the C64 compatible printer.  The parts needed are one DB25
  16. male connector (Radio Shack #276-1429), one 6 pin DIN plug (RS #274-020), and
  17. some six conductor cable (RS #278-874 or equivalent).  Note that the cable
  18. length should be kept to less than six feet.  The wiring connections and signal
  19. descriptions for this cable are given as follows:
  20.  
  21. Commodore 64 DIN plug pin:    Parallel printer DB25 connector pin:
  22.     1 (SRQ IN)                    2 (DATA0)
  23.     2 (GND)                       20 (GND)
  24.     3 (SER ATN)                   3 (DATA1)
  25.     4 (SER CLK)                   4 (DATA2)
  26.     5 (SER DAT)                   5 (DATA3)
  27.     6 (RST)                       6 (DATA4)
  28.  
  29. The software uses the PC parallel port to emulate a C64 serial port.  The
  30. example program, C64.C (Listing 1), is written in Borland's Turbo C.  It reads
  31. input and sends each character to the printer.  It can be used as a filter in
  32. an MS-DOS command line pipe.  For example, DOS commands such as:  dir | c64
  33. would print a directory listing, or type a_file | c64 would print the contents
  34. of a file.
  35.  
  36. I have also written an MS-DOS device driver which can be used to allow any PC
  37. application to print to a C64 compatible printer, and it supports multiple
  38. printers connected to a single PC parallel port.  The listing for this software
  39. is too lengthy to print, however I will make this software and assembled cables
  40. available to Commodore 64 enthusiasts for a nominal charge; just write me for
  41. details.  With these C64 compatible printers often selling for less than $25 at
  42. garage sales and flea markets, it's easy to add a couple of additional
  43. "scratch" printers to any PC system.
  44.  
  45. John Keyerleber
  46. 26300 Chardonview Drive
  47. Cleveland, OH  44143
  48. (216) 261-9676
  49. E-mail:  jkeyerleber@bailey.com
  50.  
  51. Listing 1:
  52.  
  53. #include <stdio.h>
  54. #include <ctype.h>
  55. #include <dos.h>
  56.  
  57. #define  PORTADR  0x378    // LPT1=0x378, LPT2 = 0x278
  58. #define  PRINTADR 0x04     // C64 compatible printer address
  59. #define  SRQ      0x01     // C64 SRQ IN signal
  60. #define  ATN      0x02     // C64 ATN signal
  61. #define  CLK      0x04     // C64 CLK signal
  62. #define  DAT      0x08     // C64 DAT signal
  63. #define  RST      0x10     // C64 RST signal
  64.  
  65. // function prototypes
  66. void initc64(void);
  67. void putc64(unsigned char);
  68. void puts64(char *);
  69. void putbyte(unsigned char, unsigned char);
  70.  
  71. // function main() loops to read input characters and send them to the printer
  72. void main(void)
  73. {
  74.     char buff[128], *ptr;
  75.  
  76.     initc64();
  77.     while(fgets(buff, 80, stdin))
  78.     {
  79.         for(ptr = buff; *ptr; putc64(*ptr++));
  80.     }
  81. }
  82.  
  83. // function init64() initializes the driver and the C64 compatible printer
  84. void initc64(void)
  85. {
  86.     // set initial port output value to all bits high
  87.     outportb(PORTADR, RST | SRQ | ATN | CLK | DAT);
  88.  
  89.     // initialize printer: RST=0, then RST=1
  90.     outportb(PORTADR, SRQ | ATN | CLK | DAT);
  91.     delay(250);
  92.     outportb(PORTADR, RST | SRQ | ATN | CLK | DAT);
  93.     delay(2250);
  94.  
  95.     // Set printer to listener: ATN and CLK low, printer will ACK with DAT low
  96.     outportb(PORTADR, RST | SRQ | DAT);
  97.     while((inportb(PORTADR) & DAT));
  98.  
  99.     // Send printer address (currently set for address 4)
  100.     putbyte(0x20 | PRINTADR, 0);
  101.  
  102.     // Send printer mode
  103.     putbyte(0x67, 0);
  104. }
  105.  
  106. // function putc64() sends a byte of data (byteval) to the C64 compatible printer
  107. void putc64(unsigned char byteval)
  108. {
  109.     // Check for upper/lower case conversion
  110.     if (isalpha(byteval))
  111.     {
  112.         byteval = (isupper(byteval)) ? tolower(byteval) : toupper(byteval);
  113.     }
  114.     // Send character
  115.     putbyte(byteval, ATN);
  116. }
  117.  
  118. // function putbyte clocks the actual byte to the C64 compatible printer bit by bit
  119. void putbyte(unsigned char byteval, unsigned char mode)
  120. {
  121.     register int bitloop;
  122.  
  123.     // Set CLK high, printer will ACK with DAT high
  124.     outportb(PORTADR, RST | SRQ | CLK | DAT | mode);
  125.     while(!(inportb(PORTADR) & DAT));
  126.  
  127.     // Loop to output bits of data
  128.     delay(1);
  129.     for (bitloop=0; bitloop<8; bitloop++)
  130.     {
  131.         outportb(PORTADR, RST | SRQ | ((byteval & 1) ? DAT : 0) | mode);
  132.         delay(1);
  133.         outportb(PORTADR, RST | SRQ | CLK | ((byteval & 1) ? DAT : 0) | mode);
  134.         delay(1);
  135.         byteval >>= 1;
  136.     }
  137.  
  138.     // Set CLK low and DAT high for end of byte, printer will ACK with DAT low
  139.     outportb(PORTADR, RST | SRQ | DAT | mode);
  140.     while((inportb(PORTADR) & DAT));
  141. }
  142.  
  143.